﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using System.Collections;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PR_SalaryDetail : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private object _dataItem = null;
        private ISalaryTypeBLL salaryTypeBLL = new SalaryTypeBLL();


        //ReadOnly property.
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            txtMin.Attributes.Add("onkeypress", "return isNumberKeyDot(event)");
            txtMax.Attributes.Add("onkeypress", "return isNumberKeyDot(event)");
            txtMinTmp.Attributes.Add("onkeypress", "return isNumberKeyDot(event)");

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblID.Text = DataBinder.Eval(DataItem, "grp_dtls_seq").ToString();

                    txtMin.Text = DataBinder.Eval(DataItem, "sal_min", "{0:N0}").ToString();
                    txtMax.Text = DataBinder.Eval(DataItem, "sal_max", "{0:N0}").ToString();
                    txtMinTmp.Text = DataBinder.Eval(DataItem, "sal_tmp", "{0:N0}").ToString();
                }
                else
                {

                }
            }
        }


        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            try
            {
                salaryTypeBLL.Insert(Session["id"].ToString(), double.Parse(txtMin.Text), double.Parse(txtMax.Text), double.Parse(txtMinTmp.Text), ssMng.EmpSeq);
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);

            }
            catch (Exception ex)
            {

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                salaryTypeBLL.Update(int.Parse(lblID.Text), double.Parse(txtMin.Text), double.Parse(txtMax.Text), double.Parse(txtMinTmp.Text), ssMng.EmpSeq);
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "mykey", "CloseAndRebind();", true);
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

    }
}